'use strict';
const db = uniCloud.database();
const _ = db.command;

exports.main = async (event, context) => {
    const { username, password } = event;
    const numPassword = Number(password);
    const res = await db.collection('users').where({
        username: username,
        password: numPassword
    }).get();
    if (res.data.length > 0) {
        const user = res.data[0];
        return {
            code: 200,
            msg: '登录成功',
            role: user.role
        };
    } else {
        return {
            code: 401,
            msg: '账号或密码错误'
        };
    }
};